package com.hiwhitley.easy.day23;

/**
 * Created by hiwhitley on 2016/10/15.
 */
public class NumberOf1Bit_191 {
    public static int hammingWeight(int n) {
        String s = Integer.toBinaryString(n);
        return s.length() - s.replaceAll("1" , "").length();
    }

    public static int hammingWeight2(int n) {
        String s = Integer.toBinaryString(n);
        int weight = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1')
                weight++;
        }
        return weight;
    }

    public static void main(String[] args) {
        System.out.println(hammingWeight2(11));
    }
}
